#include <iostream>
#include <algorithm>
using namespace std;

const int N = 2e5 + 10;
int a[N];

int main() {
    int n,k;
    cin >> n >> k;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    sort(a + 1,a + 1 + n);
    int l = 1,r = 1,maxlen = 1;
    while(r <= n)
    {
        while(a[r] - a[l] > k)
        {
            l++;
        }
        maxlen = max(maxlen,r - l + 1);
        r++;
    }
    cout << maxlen << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")